package a2_p04_ak_fh;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import org.jgrapht.WeightedGraph;
import org.jgrapht.graph.DefaultWeightedEdge;
import org.jgrapht.graph.WeightedMultigraph;

public class GraphUtil {

	public WeightedGraph<AttVertex, DefaultWeightedEdge> addUndirectedEdges(
			WeightedGraph<AttVertex, DefaultWeightedEdge> graph) {

		WeightedGraph<AttVertex, DefaultWeightedEdge> res = new WeightedMultigraph<AttVertex, DefaultWeightedEdge>(
				DefaultWeightedEdge.class);

		// Get Vertices
		for (DefaultWeightedEdge e : graph.edgeSet()) {
			AttVertex s = graph.getEdgeSource(e);
			AttVertex t = graph.getEdgeTarget(e);
			res.addVertex(s);
			res.addVertex(t);

			DefaultWeightedEdge e2 = res.addEdge(s, t);
			res.setEdgeWeight(e2, res.getEdgeWeight(e));

			DefaultWeightedEdge e3 = res.addEdge(t, s);
			res.setEdgeWeight(e3, res.getEdgeWeight(e));
		}

		return res;

	}

	public Set<DefaultWeightedEdge> getTouchingEdges(
			WeightedGraph<AttVertex, DefaultWeightedEdge> graph,
			AttVertex vertex) {

		Set<DefaultWeightedEdge> touchingEdges = new HashSet<DefaultWeightedEdge>();

		for (DefaultWeightedEdge e : graph.edgeSet()) {
			if (graph.getEdgeSource(e).getName().equals(vertex.getName())
					|| graph.getEdgeTarget(e).getName()
							.equals(vertex.getName())) {
				touchingEdges.add(e);
			}
		}
		
		return touchingEdges;
	}

}
